﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Module;
using BLL;
using BLL.Common;

namespace Admin
{
    /// <summary>
    /// AuthHelper 的摘要说明
    /// </summary>
    public class AuthHelper
    {
        public AuthHelper() { }

        /// <summary>
        /// 获取当前登录用户信息
        /// </summary>
        public static UserPassportInfo CurrentUserInfo
        {
            get
            {
                if (HttpContext.Current.Session["UserLoginInfo"] != null)
                {
                    return (UserPassportInfo)HttpContext.Current.Session["UserLoginInfo"];
                }
                else
                {
                    return null;
                }
            }
        }

        /// <summary>
        /// 获取当前登录用户ID
        /// </summary>
        public static long CurrentUserPassportId
        {
            get
            {
                if (HttpContext.Current.Session["UserLoginInfo"] != null)
                {
                    return ((UserPassportInfo)HttpContext.Current.Session["UserLoginInfo"]).UserPassportId;
                }
                else
                {
                    return 0;
                }
            }
        }


        /// <summary>
        /// 当前用户Session检验
        /// </summary>
        /// <param name="page">当前页面回话</param>
        /// <param name="moduleId">当前操作模块ID</param>
        public static void SessionCheck()
        {
            if (HttpContext.Current.Session["UserLoginInfo"] == null)
            {
                string path = Contexts.AdminPath + "/Login.aspx";
                string thisUrl = Contexts.ThisPageUrlWithParams;
                path += "?goUrl=" + HttpContext.Current.Server.UrlEncode(thisUrl);
                HttpContext.Current.Response.Redirect(path, true);
                return;
            }
        }
    }
}


